import Vue from 'vue'
import Vuex from 'vuex'
import actions from '../actions/order'
import  {
  UPDATE_ORDER_FILTER_DATA
} from '../mutation-types'

const EMPTY_SPACE = ' '
const dateFormat = require('dateformat')

Vue.use(Vuex)

const getLastYear = (date) => {
  let lastYearDate = new Date()
  let year =  (date || lastYearDate).getFullYear() - 1
  lastYearDate.setFullYear(year)
  return dateFormat(lastYearDate, 'yyyy-mm-dd HH:MM:ss')
}

const state = {
  orderFilterData: {
    team_id: EMPTY_SPACE,
    type: EMPTY_SPACE,
    pay_time: [getLastYear(), dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')],
    suid: null,
    is_new: null,
  },
}

const mutations = {
  [UPDATE_ORDER_FILTER_DATA] (state, data) {
    state.orderFilterData = data
  }
}

export default {
  state,
  mutations,
  actions
}
